package com.sqm.task.task;


import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
import com.dingtalk.api.response.OapiRobotSendResponse;
import com.taobao.api.ApiException;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableScheduling
public class HealthDingTask {

    private String serverUrl = "https://oapi.dingtalk.com/robot/send?access_token=561c5e7db286f9eea8d9ec4672dbcd38d44982edc0d3ff6006c3b956cc571799";

    private String messagaeUrl = "http://192.168.2.252:6666/index";

    private String picUrl = "";

    private String text = "减压操时间到，时间:15分钟,请开始你的表演";

    private String title = "拾起卖健康小助手";


    @Scheduled(cron ="30 44 9 * * ?")
    public void  cronTask1() throws ApiException {
       execute();

    }

    @Scheduled(cron ="0 0 15 * * ?")
    public void  cronTask2() throws ApiException {
        execute();

    }
    public void execute() throws ApiException {
        DingTalkClient client = new DefaultDingTalkClient(serverUrl);
        OapiRobotSendRequest request = new OapiRobotSendRequest();
        request.setMsgtype("link");

        OapiRobotSendRequest.Link link = new OapiRobotSendRequest.Link();

        link.setMessageUrl(messagaeUrl);
        link.setPicUrl("http://192.168.2.252:6666/picture/1.jpg");
        link.setTitle(title);
        link.setText(text);


        request.setLink(link);

        OapiRobotSendResponse response = client.execute(request);
    }



}
